﻿
using System;
using System.Collections.Generic;

namespace hCommand {
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：LocSelect                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2021/9/8 16:59:49                        
   *└────────────────────────────────────────────────┘
   **/
    public class CoreDataUtil {
        public static long getStockId<CSD>(List<CSD> detailList) where CSD : AbsCoreStockDetail, new() {
            if( detailList == null || detailList.Count == 0 ) {
                throw new Exception("该物料库存不存在,无法生成出库任务");
            }
            long stockId = 0;
            foreach( CSD csd in detailList ) {
                if( csd.stockId == 0 ) {
                    throw new Exception(csd.id + "stock 不存在");
                }
                if( stockId != 0 && csd.stockId != stockId ) {
                    throw new Exception(stockId + "不在一个货位");
                }
                stockId = ( int ) csd.stockId;
            }
            foreach( var stockDetail in detailList ) {
                if( stockDetail.storeStatus != ( int ) StockStatus.库存 ) {
                    throw new Exception(stockDetail.id + " 库存状态为" + ( StockStatus ) stockDetail.storeStatus + ",明细无法生成出库任务");
                }
            }
            return stockId;
        }

    }
}
